"use strict";
const way = require("../utils/way");
const Result = require("../basics/result");

/**
 * 模板实例化
 * @param {*} cloud 
 * @param {*} param1 
 */
exports.instantiate = async (cloud, session, { description, template_id, template_version }) => {
  let param_mini_app_instantiate_template_app_simple_request = { description, template_id, template_version };
  let data = { param_mini_app_instantiate_template_app_simple_request, session };
  console.log("temp instantiate params", data);
  const res = await way.taobao(cloud, "taobao.miniapp.widget.template.instantiate", data);
  console.log("temp instantiate results", res);
  if (res.result && res.result.success) {
    return true;
  }
  // const error = results.error_response;
  // if (error) {
  //   throw Result.error(Result.constant.taobaofail, error.sub_msg);
  // }
  throw Result.error(Result.constant.taobaofail, res.result.err_message);
};

/**
 * 更新实例化
 * @param {*} cloud 
 * @param {*} param1 
 */
exports.updateapp = async (cloud, session, { entity_id, template_id, template_version }) => {
  let param_mini_app_instantiate_template_app_update_request = { entity_id, template_id, template_version };
  let data = { param_mini_app_instantiate_template_app_update_request, session };
  console.log("temp updateapp params", data);
  const results = await way.taobao(cloud, "taobao.miniapp.widget.template.instance.update", data);
  console.log("temp updateapp results", results);
  if (res.result && res.result.success) {
    return true;
  }
  throw Result.error(Result.constant.taobaofail, res.result.err_message);
};



